package com.she.component.adapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;

public class GeneralExpandableAdapter extends BaseExpandableListAdapter {

	List<?> mGroupData = new ArrayList<Object>();
	Map<?,?>  mChildData = new HashMap<Object,Object>();
	
	public void setGroupData(List<Object> groupData) {
		if(groupData != null) mGroupData = groupData;
	}
	
	public void setChildData(Map<?,?> childData) {
		if(childData != null) mChildData = childData;
	}
	
	@Override
	public Object getChild(int groupPosition, int childPosition) {
		Object group = mGroupData.get(groupPosition);
		if(mChildData.containsKey(group)) {
			List<?> child = (List<?>)(mChildData.get(group));
			return child.get(childPosition);
		}
		return null;
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		return childPosition;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
		return null;
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		Object group = mGroupData.get(groupPosition);
		if(mChildData.containsKey(group)) {
			List<?> child = (List<?>)(mChildData.get(group));
			if(child != null) return child.size();
		}
		return 0;
	}

	@Override
	public Object getGroup(int groupPosition) {
		return mGroupData.get(groupPosition);
	}

	@Override
	public int getGroupCount() {
		return mGroupData.size();
	}

	@Override
	public long getGroupId(int groupPosition) {
		return groupPosition;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
		return null;
	}

	@Override
	public boolean hasStableIds() {
		return true;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		return true;
	}
}
